﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace ReportGenerators
{
    public partial class FrmChiTieuBaoCaoTaiChinh : BasicForms.FrmBase
    {
        public FrmChiTieuBaoCaoTaiChinh()
        {
            InitializeComponent();
        }

        private void FrmChiTieuBaoCaoTaiChinh_Load(object sender, EventArgs e)
        {
            if (DesignMode) return;
            try
            {
                chiTieuBaoCaoTaiChinhTableAdapter.Connection.ConnectionString = GeneralLibs.LocalSettings.ConnectString;
                baoCaoTableAdapter.Connection.ConnectionString = GeneralLibs.LocalSettings.ConnectString;
                baoCaoTableAdapter.Fill(accountingDataSet.BaoCao);
                lookUpEditBaoCaoTaiChinh.EditValue = accountingDataSet.BaoCao.Rows[0]["BaoCaoID"];
            }
            catch (Exception ex)
            {
                BasicForms.FrmExceptionNotifier.ShowAndLog(ex);
            }
            finally
            {
            }
        }

        private void lookUpEditBaoCaoTaiChinh_EditValueChanged(object sender, EventArgs e)
        {
            accountingDataSet.ChiTieuBaoCaoTaiChinh.Clear();
            SqlConnection con = new SqlConnection(GeneralLibs.LocalSettings.ConnectString);
            try
            {
                con.Open();
                SqlCommand cmd = con.CreateCommand();
                cmd.CommandText = "SELECT * FROM ChiTieuBaoCaoTaiChinh WHERE BaoCaoID = " + (lookUpEditBaoCaoTaiChinh.EditValue).ToString();
                SqlDataAdapter da = new SqlDataAdapter(cmd);
                da.Fill(accountingDataSet.ChiTieuBaoCaoTaiChinh);
            }
            catch (Exception ex)
            {
                BasicForms.FrmExceptionNotifier.ShowAndLog(ex);
            }
            finally
            {
                con.Close();
            }
        }

        private void btnUpdate_Click(object sender, EventArgs e)
        {
            try
            {
                foreach (DataRow row in this.accountingDataSet.ChiTieuBaoCaoTaiChinh.Rows)
                {
                    if (row.RowState ==  DataRowState.Modified)
                    {
                        row["BaoCaoID"] = (int)(lookUpEditBaoCaoTaiChinh.EditValue);
                    }
                }
                this.chiTieuBaoCaoTaiChinhBindingSource.EndEdit();
                this.chiTieuBaoCaoTaiChinhTableAdapter.Update(this.accountingDataSet.ChiTieuBaoCaoTaiChinh);
            }
            catch (Exception ex)
            {
                BasicForms.FrmExceptionNotifier.ShowAndLog(ex);
            }
            finally
            {
            }
        }

        private void btnClose_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}
